home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility3 / rx.zip / RX.C < prev    next >
Text File  |  1991-09-30  |  48KB  |  1,532 lines

  1. /*--------------------------------------------------------------------      */
  2. /* rxvar.h                                                                  */
  3. /*NOTE:                                                                     */
  4. /*This is a completly experimental program in it's pre-beta version.        */
  5. /*It is not guaranteed to work properly under all circumstances, although   */
  6. /*it has been tested for a couple of weeks. Everyone who uses this program  */
  7. /*does this on his own risk, so if your machine explodes, don't tell me     */
  8. /*you didn't know.                                                          */
  9. /*                                                                          */
  10. /*Andreas Gruen releases this software "as is", with no express or          */
  11. /*implied warranty, including, but not limited to, the implied warranties   */
  12. /*of merchantability and fitness for a particular purpose.                  */
  13. /*                                                                          */
  14. /*This program is completly free for everyone.                              */
  15. /*You can do with it and its sources whatever you want, but it would        */
  16. /*be fine to leave my name somewhere in the program or startup-banner.      */
  17. /*---------------------------------------------------------------------     */
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include "rx.h"
  21. #include "rxvar.h"
  22.  
  23. char copyleft[] = " (c) Copyright Andreas Gruen 1991.  All rights reserved.";
  24.  
  25. #define EXIT(X) {fprintf(stderr,"RX: %s\n",X);exit(1);}
  26.  
  27. #define ALIGN(X,Y) ( (ULONG)(X) << (Y) )    /* align to 2^Y   */
  28.  
  29. #define TMPSIZE 16384
  30.  
  31. #define MAX(X,Y) (((X) > (Y)) ? (X) : (Y))   /* for those who don't have it*/
  32. #define MIN(X,Y) (((X) < (Y)) ? (X) : (Y))
  33.  
  34. #define GOT_TEXT 0
  35. #define GOT_ID   1
  36.  
  37. #define MEMF_DISC  0x1000         /* memory-options*/
  38. #define MEMF_MOVE  0x0010
  39. #define MEMF_PREL  0x0040
  40. #define FLAG_MASK  0x1050
  41.  
  42. DOSHEAD doshead;             /* DOS EXE-header*/
  43. OSHEAD oshead;               /* WIN/ OS2-header*/
  44. UCHAR tmpbuf[TMPSIZE];
  45. int filenum;
  46. char verbose = 0;
  47. char *resname[16] = { "---","CURSOR","BITMAP","ICON","MENU","DIALOG",
  48.                       "STRING","FONTDIR","FONT","ACCELERATOR","RCDATA",
  49.                       "(unknown)-11-","CURSORHEADER","(unknown)-13-",
  50.                       "ICONHEADER","NAMETABLE" };
  51.  
  52. char *stdclassname[6] = { "button","edit","static",
  53.                         "listbox","scrollbar","combobox" };
  54.  
  55. char spaces[] =
  56.   "                                                                ";
  57.  
  58. USHORT ntentry = 0;
  59. #define MAXSPACE 64
  60. #define SPC(X) (spaces + (MAXSPACE-(X)))
  61. #define INDENTVAL 2
  62. #define IS_MENUOPT (MF_GRAYED|MF_DISABLED|MF_CHECKED|MF_MENUBARBREAK|MF_MENUBREAK)
  63.  
  64. int get_rctab(FILE*);
  65. int get_lstrings(FILE*);
  66. int get_rcentry(FILE *,USHORT);
  67.  
  68. int put_icon(FILE *,FILE *,long);
  69. int put_font(FILE *,FILE *,long);
  70. int put_bitmap(FILE *,FILE *,long);
  71. int put_cursor(FILE *,FILE *,long);
  72. int put_menu(FILE *,FILE *,long,char *,USHORT,USHORT);
  73. int put_dialog(FILE *,FILE *,long,char *,USHORT,USHORT);
  74. int put_nametab(FILE *,FILE *,long);
  75. int put_strings(FILE *,FILE *,long,char *,USHORT,USHORT);
  76. int put_rcdata(FILE *,FILE *,long,long,char *,USHORT,USHORT);
  77. int put_accel(FILE *,FILE *,long,char *,USHORT,USHORT);
  78.  
  79. int print_styles(FILE *,ULONG,UCHAR);
  80. char *lookup_name(RCENTRY *, USHORT);
  81. char * get_virttext(UCHAR);
  82. int read_string(FILE *,char *);
  83. int read_nstring(FILE *,char *,USHORT);
  84. USHORT read_word(FILE *);
  85. ULONG read_dword(FILE *);
  86. UCHAR read_byte(FILE *);
  87. int copy_block(FILE * ,FILE *, ULONG);
  88. int read_textorid(FILE *,char*,int *);
  89.  
  90. int iflg,mflg,cflg,bflg,dflg,sflg,fflg,aflg,nflg,rflg;
  91. int i_num,m_num,c_num,b_num,d_num,s_num,f_num,a_num,n_num,r_num,xtract;
  92.  
  93. char base_file[128],rc_file[128], temp_name[128];
  94. char exe_file[128];
  95. FILE *fprc;                /* .RC-File  */
  96. main(argc,argv)
  97.   int argc;
  98.   char *argv[];
  99.   {
  100.     int i,n;
  101.     FILE *fp;
  102.     USHORT dossign,ossign;
  103.     ULONG newhead;
  104.     char *s;
  105.  
  106.     dossign = *( (USHORT *)"MZ");       /* well, hum, but it works*/
  107.     ossign = *( (USHORT *)"NE");
  108.  
  109.     nflg = iflg = mflg = cflg = bflg = dflg = 0;
  110.     sflg = fflg = aflg = rflg = 0;
  111.     n_num = i_num = m_num = c_num = b_num = d_num = 0;
  112.     s_num = f_num = a_num = r_num = 0;
  113.     xtract = 0;
  114.  
  115.     while(--argc > 0 && (*++argv)[0] == '-')
  116.       {
  117.         for(s = (*argv)+1; *s && argc > 0 ; s++)
  118.           {
  119.             switch(*s)
  120.               {
  121.                 case 'i':
  122.                  iflg = xtract = 1;
  123.                  break;
  124.                 case 'm':
  125.                  mflg = xtract = 1;
  126.                  break;
  127.                 case 'c':
  128.                  cflg = xtract = 1;
  129.                  break;
  130.                 case 'b':
  131.                  bflg = xtract = 1;
  132.                  break;
  133.                 case 'd':
  134.                  dflg = xtract = 1;
  135.                  break;
  136.                 case 's':
  137.                  sflg = xtract = 1;
  138.                  break;
  139.                 case 'f':
  140.                  fflg = xtract = 1;
  141.                  break;
  142.                 case 'a':
  143.                  aflg = xtract = 1;
  144.                  break;
  145.                 case 'n':
  146.                  nflg = 1;
  147.                  break;
  148.                 case 'r':
  149.                  rflg = xtract = 1;
  150.                  break;
  151.                 case 'x':
  152.                  nflg = iflg = mflg = cflg = bflg = dflg = 1;
  153.                  sflg = fflg = aflg = rflg = xtract = 1;
  154.                  break;
  155.                 case 'v':
  156.                   verbose = 1;
  157.                   break;
  158.                 case '?':
  159.                 case 'h':
  160.                   argc = -1;
  161.                   break;
  162.                 default:
  163.                   fprintf(stderr,"illegal option '%c'\n",*s);
  164.                   argc = -1;
  165.                   break;
  166.               }
  167.          }
  168.       }
  169.     if(argc <= 0)
  170.       {
  171.         fprintf(stderr,"Usage: RX -{ibcmdsfav} filename [outputname]\n");
  172.         fprintf(stderr,"             -i   : extract ICONs\n");
  173.         fprintf(stderr,"             -b   : extract BITMAPs\n");
  174.         fprintf(stderr,"             -c   : extract CURSORs\n");
  175.         fprintf(stderr,"             -m   : extract MENUs\n");
  176.         fprintf(stderr,"             -d   : extract DIALOGs\n");
  177.         fprintf(stderr,"             -s   : extract STRINGTABLEs\n");
  178.         fprintf(stderr,"             -f   : extract FONTs\n");
  179.         fprintf(stderr,"             -a   : extract ACCELERATORS\n");
  180.         fprintf(stderr,"             -n   : extract NAMETABLE (internal use)\n");
  181.         fprintf(stderr,"             -r   : extract RCDATA\n");
  182.         fprintf(stderr,"             -x   : extract all\n");
  183.         fprintf(stderr,"             -v   : verbose mode\n");
  184.         fprintf(stderr,"separate files wil be created and\n");
  185.         fprintf(stderr,"#include'd in RC-File\n");
  186.         exit(1);
  187.       }
  188.  
  189.     strcpy(exe_file,argv[0]);
  190.     strupr(exe_file);
  191.     if( (fp = fopen(exe_file,"rb")) == NULL)
  192.       {
  193.         strcat(exe_file,".EXE");
  194.         if( (fp = fopen(exe_file,"rb")) == NULL)
  195.           EXIT("can't open infile");
  196.       }
  197.     printf("RX: %s\n",copyleft);
  198.     printf("Processing  '%s'\n",exe_file);
  199.     if(argc > 1)
  200.       {
  201.         strcpy(base_file,argv[1]);
  202.       }
  203.     else
  204.       {
  205.         strcpy(base_file,exe_file);
  206.       }
  207.     /* look if there's an ext. (like .EXE),
  208.        ext. are 4 chars max including '.'
  209.        if yes : strip it */
  210.  
  211.     s = base_file + strlen(base_file) - 4;
  212.     while(*s)
  213.       {
  214.         if(*s == '.')
  215.           {
  216.             *s = '\0';   /* strip*/
  217.             break;       /* and go */
  218.           }
  219.         s++;
  220.       }
  221.  
  222.     if(xtract)
  223.       {
  224.         strcpy(temp_name,base_file);
  225.         strcat(temp_name,".rc");
  226.       }
  227.     else
  228.       {
  229.         strcpy(temp_name,"NUL");       /* no output,
  230.                                           could be coded better, I know
  231.                                           (sigh) */
  232.       }
  233.     if( (fprc = fopen(temp_name,"w")) == NULL)  EXIT("can't open RC-file");
  234.  
  235.     fprintf(fprc,"#include <windows.h>\n\n");   /* must be*/
  236.  
  237.     fread(&doshead,sizeof(DOSHEAD),1,fp);
  238.  
  239.     if(doshead.sign != dossign)    EXIT("Invalid file (no EXE, DLL...)");
  240.  
  241.     if(verbose)
  242.       printf("Header-Size : %ld \n",(ULONG)(doshead.nparhead) << 4);
  243.  
  244.     if(doshead.posreloc != 0x40)
  245.       {
  246.         fclose(fp);
  247.         EXIT("No Windows/OS2-executable or lib");       /*DOS-Exe*/
  248.       }
  249.  
  250.     newhead = doshead.posnewhead;
  251.     if(verbose)
  252.       printf("OS-Header at : %lX \n",newhead);
  253.  
  254.     fseek(fp,newhead,0);
  255.     fread(&oshead,sizeof(OSHEAD),1,fp);
  256.  
  257.     if(oshead.sign != ossign)
  258.       EXIT("Invalid file (no EXE, DLL...) [new header]");
  259.  
  260.     build_nametable(fp);
  261.  
  262.     get_rctab(fp);     /* view/extract resources*/
  263.  
  264.     fclose(fp);
  265.     fclose(fprc);
  266.     return(0);
  267.   }
  268. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  269.  
  270. get_rctab(fp)
  271.   FILE *fp;
  272.   {
  273.     USHORT rcalign;
  274.     ULONG rctab;
  275.  
  276.     rctab = (ULONG)oshead.posrctab+doshead.posnewhead;
  277.     if(verbose)
  278.       printf("Resourcetable at offset: %04lX\n",rctab);
  279.  
  280.     fseek(fp,rctab,0);
  281.     rcalign = read_word(fp);        /* padding size = 2^rcalign bytes*/
  282.  
  283.     if(verbose)
  284.       printf("Resource-alignment = %d bytes\n",1<<rcalign);
  285.     while(get_rcentry(fp,rcalign));
  286.     get_lstrings(fp);
  287.     return(0);
  288.   }
  289. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  290.  
  291. build_nametable(fp)
  292.   FILE *fp;
  293.   {
  294.     USHORT rcalign;
  295.     ULONG rctab;
  296.     RCENTRY rce;
  297.     USHORT rctyp,nrc,i;
  298.     long tpos,tlen;
  299.  
  300.     rctab = (ULONG)oshead.posrctab+doshead.posnewhead;
  301.  
  302.     fseek(fp,rctab,0);
  303.     rcalign = read_word(fp);        /* padding size = 2^rcalign bytes*/
  304.  
  305.     rctyp = read_word(fp);
  306.     ntentry = 0;
  307.     while(rctyp)
  308.       {
  309.         nrc = read_word(fp);
  310.         read_dword(fp);               /*skip reserved bytes*/
  311.         if((rctyp & 0x7fff) == 0x000f)   /* joop, we have it*/
  312.           {
  313.             for(i = 0; i < nrc; i++)
  314.               {
  315.                 fread(&rce,sizeof(RCENTRY),1,fp);
  316.                 tpos = ALIGN(rce.datp,rcalign);
  317.                 tlen = ALIGN(rce.len,rcalign);
  318.                 fill_ntable(fp,tpos);
  319.               }
  320.             break;
  321.           }
  322.         else
  323.           {
  324.             fseek(fp,(ULONG)sizeof(RCENTRY)*(ULONG)nrc,1);  /*skip it*/
  325.           }
  326.         rctyp = read_word(fp);
  327.       }
  328.     return(ntentry);
  329.   }
  330. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  331.  
  332. int fill_ntable(fp,filep)
  333.   FILE *fp;
  334.   long filep;
  335.   {
  336.     long fpos;
  337.     char xname[16];
  338.     char rcname[256];
  339.     USHORT len,rctype,rcnum,i;
  340.     long filelen;
  341.  
  342.     fpos = ftell(fp);
  343.  
  344.     fseek(fp,filep,0);
  345.  
  346.     while(len = read_word(fp))
  347.       {
  348.         rctype = read_word(fp);
  349.         rctype &= 0x000f;
  350.         rctype %= 11;             /* refs to icons are refs to iconheaders
  351.                                      same for bitmaps, think about that */
  352.         nametab[ntentry].type = rctype;
  353.         nametab[ntentry].num = read_word(fp) & 0x7fff;
  354.         read_byte(fp);            /* skip 1 byte */
  355.         fread(nametab[ntentry].name,1,len-7,fp);
  356.                  /* may use read_string, but this is safe*/
  357.         ntentry++;
  358.       }
  359.     fseek(fp,fpos,0);
  360.     return(0);
  361.   }
  362. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  363.  
  364. get_lstrings(fp)
  365.   FILE *fp;
  366.   {
  367.     UCHAR clen;
  368.     USHORT len;
  369.     char buff[256];
  370.  
  371.     while(clen = read_byte(fp))
  372.       {
  373.         read_nstring(fp,buff,(USHORT)clen);
  374.         printf("Resource-Name : %s\n",buff);
  375.       }
  376.     return(0);
  377.   }
  378.  
  379. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  380.  
  381. get_rcentry(fp,rcalign)
  382.   FILE *fp;
  383.   USHORT rcalign;
  384.   {
  385.  
  386.     RCENTRY rce;
  387.     FILE *fpout;
  388.     USHORT rctyp,nrc,i;
  389.     char *pname;
  390.     long tpos,tlen;
  391.  
  392.     fread(&rctyp,2,1,fp);
  393.     if(rctyp == 0)   return(0);    /* got all */
  394.  
  395.     fread(&nrc,2,1,fp);
  396.     fread(tmpbuf,1,4,fp);          /*reserved bytes*/
  397.  
  398.  
  399.     if((rctyp & 0x7fff) < 16)
  400.       {
  401.         printf("%u %s (s)\n",nrc,resname[rctyp & 0xf]);
  402.       }
  403.     else
  404.       {
  405.         printf("unknown resource-type %04X (%u resources)\n",nrc,rctyp);
  406.       }
  407.  
  408.     for(i = 0; i < nrc; i++)
  409.       {
  410.         fread(&rce,sizeof(RCENTRY),1,fp);
  411.         tpos = ALIGN(rce.datp,rcalign);
  412.         tlen = ALIGN(rce.len,rcalign);
  413.         if(verbose)
  414.           printf("offset %04lX  len = %lu ord= %04X flags=%04X\n"
  415.                  ,tpos,tlen,rce.id,rce.flags);
  416.  
  417. /* extract it */
  418.         switch(rctyp & 0x0fff)
  419.           {
  420.             case 0x0001:               /*CURSOR-resource*/
  421.               if(cflg)
  422.                 {
  423.                   sprintf(temp_name,"CURS%d.CUR",c_num++);
  424.                   if((fpout = fopen(temp_name,"wb")) == NULL)  EXIT("file-write failed");
  425.                   put_cursor(fp,fpout,tpos);
  426.                   fclose(fpout);
  427.                   rce.id--;         /* don't ask me why
  428.                                        but cursor-numbers start with 2*/
  429.                   if(pname = lookup_name(&rce,rctyp))
  430.                     fprintf(fprc,"%s CURSOR ",pname);
  431.                   else
  432.                     fprintf(fprc,"%d CURSOR ",rce.id & 0x7fff);
  433.                   print_flags(fprc,rce.flags,rctyp & 0x0f);
  434.                   fprintf(fprc,"%s\n",temp_name);
  435.                 }
  436.               break;
  437.             case 0x0002:               /*BITMAP-resource*/
  438.               if(bflg)
  439.                 {
  440.                   sprintf(temp_name,"BITM%d.BMP",b_num++);
  441.                   if((fpout = fopen(temp_name,"wb")) == NULL)  EXIT("file-write failed");
  442.                   put_bitmap(fp,fpout,tpos);
  443.                   fclose(fpout);
  444.                   if(pname = lookup_name(&rce,rctyp))
  445.                     fprintf(fprc,"%s BITMAP ",pname);
  446.                   else
  447.                     fprintf(fprc,"%d BITMAP ",rce.id & 0x7fff);
  448.                   print_flags(fprc,rce.flags,rctyp & 0x0f);
  449.                   fprintf(fprc,"%s\n",temp_name);
  450.                 }
  451.               break;
  452.             case 0x0003:               /*ICON-resource*/
  453.               if(iflg)
  454.                 {
  455.                   sprintf(temp_name,"ICON%d.ICO",i_num++);
  456.                   if((fpout = fopen(temp_name,"wb")) == NULL)  EXIT("file-write failed");
  457.                   put_icon(fp,fpout,tpos);
  458.                   fclose(fpout);
  459.                   if(pname = lookup_name(&rce,rctyp))
  460.                     fprintf(fprc,"%s ICON ",pname);
  461.                   else
  462.                     fprintf(fprc,"%d ICON ",rce.id & 0x7fff);
  463.                   print_flags(fprc,rce.flags,rctyp & 0x0f);
  464.                   fprintf(fprc,"%s\n",temp_name);
  465.                 }
  466.               break;
  467.             case 0x0008:               /*FONT-resource  */
  468.               if(fflg)
  469.                 {
  470.                   sprintf(temp_name,"FONT%d.FNT",f_num++);
  471.                   if((fpout = fopen(temp_name,"wb")) == NULL)  EXIT("file-write failed");
  472.                   put_font(fp,fpout,tpos);
  473.                   fclose(fpout);
  474.                   /* fonts don't have names*/
  475.                   fprintf(fprc,"%d FONT ",rce.id & 0x7fff);
  476.                   print_flags(fprc,rce.flags,rctyp & 0x0f);
  477.                   fprintf(fprc,"%s\n",temp_name);
  478.                 }
  479.               break;
  480.             case 0x0004:               /*MENU-resource */
  481.               if(mflg)
  482.                 {
  483.                   strcpy(temp_name,base_file);
  484.                   strcat(temp_name,".MEN");
  485.                   if(mflg++ == 1)    /* first menu should overwrite*/
  486.                     {
  487.                       fprintf(fprc,"#include \"%s\"\n",temp_name);
  488.                       if((fpout = fopen(temp_name,"w")) == NULL)
  489.                         EXIT("file-write failed");
  490.                     }
  491.                   else
  492.                     {
  493.                       if((fpout = fopen(temp_name,"a")) == NULL)
  494.                         EXIT("file-write failed");
  495.                     }
  496.                   pname = lookup_name(&rce,rctyp);
  497.                   put_menu(fp,fpout,tpos,pname,rce.id & 0x7fff,rce.flags);
  498.                   fclose(fpout);
  499.                 }
  500.               break;
  501.             case 0x0005:               /*DIALOG-resource */
  502.               if(dflg)
  503.                 {
  504.                   strcpy(temp_name,base_file);
  505.                   strcat(temp_name,".DLG");
  506.                   if(dflg++ == 1)    /* first should overwrite*/
  507.                     {
  508.                       fprintf(fprc,"#include \"%s\"\n",temp_name);
  509.                       if((fpout = fopen(temp_name,"w")) == NULL)
  510.                         EXIT("file-write failed");
  511.                     }
  512.                   else
  513.                     {
  514.                       if((fpout = fopen(temp_name,"a")) == NULL)
  515.                         EXIT("file-write failed");
  516.                     }
  517.                   pname = lookup_name(&rce,rctyp);
  518.                   put_dialog(fp,fpout,tpos,pname,rce.id & 0x7fff,rce.flags);
  519.                   fclose(fpout);
  520.                 }
  521.               break;
  522.             case 0x0006:               /*STRING-resource*/
  523.               if(sflg)
  524.                 {
  525.                   strcpy(temp_name,base_file);
  526.                   strcat(temp_name,".STR");
  527.                   if(sflg++ == 1)    /* first should overwrite*/
  528.                     {
  529.                       fprintf(fprc,"#include \"%s\"\n",temp_name);
  530.                       if((fpout = fopen(temp_name,"w")) == NULL)
  531.                         EXIT("file-write failed");
  532.                     }
  533.                   else
  534.                     {
  535.                       if((fpout = fopen(temp_name,"a")) == NULL)
  536.                         EXIT("file-write failed");
  537.                     }
  538.                   pname = lookup_name(&rce,rctyp);
  539.                   put_strings(fp,fpout,tpos,pname,rce.id & 0x7fff,rce.flags);
  540.                   fclose(fpout);
  541.                 }
  542.               break;
  543.             case 0x0007:               /*FONTDIR-resource,
  544.                                          not implemented*/
  545.               break;
  546.             case 0x0009:               /*ACCEL-resource*/
  547.               if(aflg)
  548.                 {
  549.                   strcpy(temp_name,base_file);
  550.                   strcat(temp_name,".ACC");
  551.                   if(aflg++ == 1)    /* first should overwrite*/
  552.                     {
  553.                       fprintf(fprc,"#include \"%s\"\n",temp_name);
  554.                       if((fpout = fopen(temp_name,"w")) == NULL)
  555.                         EXIT("file-write failed");
  556.                     }
  557.                   else
  558.                     {
  559.                       if((fpout = fopen(temp_name,"a")) == NULL)
  560.                         EXIT("file-write failed");
  561.                     }
  562.                   pname = lookup_name(&rce,rctyp);
  563.                   put_accel(fp,fpout,tpos,pname,rce.id & 0x7fff,rce.flags);
  564.                   fclose(fpout);
  565.                 }
  566.               break;
  567.             case 0x000a:               /*RCDATA-resource */
  568.               if(rflg)
  569.                 {
  570.                   strcpy(temp_name,base_file);
  571.                   strcat(temp_name,".RCD");
  572.                   if(rflg++ == 1)    /* first should overwrite*/
  573.                     {
  574.                       fprintf(fprc,"#include \"%s\"\n",temp_name);
  575.                       if((fpout = fopen(temp_name,"w")) == NULL)
  576.                         EXIT("file-write failed");
  577.                     }
  578.                   else
  579.                     {
  580.                       if((fpout = fopen(temp_name,"a")) == NULL)
  581.                         EXIT("file-write failed");
  582.                     }
  583.                   pname = lookup_name(&rce,rctyp);
  584.                   put_rcdata(fp,fpout,tpos,tlen,pname,rce.id & 0x7fff,rce.flags);
  585.                   fclose(fpout);
  586.                 }
  587.               break;
  588.             case 0x000c:               /*CURSOR-header-resource,
  589.                                          undocumented, not needed*/
  590.               break;
  591.             case 0x000e:               /*ICON-header-resource,
  592.                                          undocumented, no need*/
  593.               break;
  594.             case 0x000f:               /*NAMETABLE-resource,
  595.                                          undocumented (?)*/
  596.               if(nflg)
  597.                 {
  598.                   strcpy(temp_name,base_file);
  599.                   strcat(temp_name,".NAM");
  600.                   if(nflg++ == 1)    /* first should overwrite*/
  601.                     {
  602.                       if((fpout = fopen(temp_name,"w")) == NULL)
  603.                         EXIT("file-write failed");
  604.                     }
  605.                   else
  606.                     {
  607.                       if((fpout = fopen(temp_name,"a")) == NULL)
  608.                         EXIT("file-write failed");
  609.                     }
  610.                   put_nametab(fp,fpout,tpos);
  611.                   fclose(fpout);
  612.                 }
  613.               break;
  614.             default:
  615.               break;
  616.           }
  617.       }
  618.     return(1);
  619.   }
  620. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  621. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  622.  
  623. int put_icon(fp,fpout,filep)
  624.   FILE *fp,*fpout;
  625.   long filep;
  626.   {
  627.     long fpos;
  628.     char xname[16];
  629.     BMHEAD dib;
  630.     ICONHEAD ih;
  631.     USHORT len;
  632.     long filelen;
  633.  
  634.     fpos = ftell(fp);
  635.  
  636.     fseek(fp,filep,0);
  637.     fread(&dib,sizeof(BMHEAD),1,fp);
  638.  
  639.     fseek(fp,filep,0);
  640.  
  641.     ih.reserv1 = 0;
  642.     ih.rctype  = 1;
  643.     ih.count   = 1;                        /*images in file*/
  644.     ih.wid     = (UCHAR)dib.width;
  645.     ih.hei     = (UCHAR)(dib.height>>1);   /*important ! AND-MASK in DIB*/
  646.     ih.colors  = (UCHAR)(1<<dib.bitcount);
  647.     ih.reserv2 = 0;
  648.     ih.xhot    = 0;                        /*reserved for icons*/
  649.     ih.yhot    = 0;
  650.     ih.DIBsize = dib.size +
  651.                  4L*(ULONG)ih.colors +    /* size of colortable*/
  652.                                           /* size of bitmap*/
  653.                  ((ULONG)ih.wid*(ULONG)ih.hei * (ULONG)dib.bitcount)/8 +
  654.                                           /*size of bitmask*/
  655.                  ((ULONG)ih.wid*(ULONG)ih.hei)/8;
  656.     ih.DIBoff  = sizeof(ICONHEAD);         /*hope for packed struct's*/
  657.  
  658.     fwrite(&ih,sizeof(ICONHEAD),1,fpout);
  659.  
  660.     copy_block(fpout,fp,ih.DIBsize);
  661.  
  662.     fseek(fp,fpos,0);
  663.     return(0);
  664.   }
  665. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  666.  
  667. int put_cursor(fp,fpout,filep)
  668.   FILE *fp,*fpout;
  669.   long filep;
  670.   {
  671.     long fpos;
  672.     char xname[16];
  673.     BMHEAD dib;
  674.     CURSORHEAD cu;
  675.     USHORT len;
  676.     long filelen;
  677.  
  678.     fpos = ftell(fp);
  679.  
  680.     fseek(fp,filep,0);
  681.     read_dword(fp);                     /* don't ask me why, skip dummy*/
  682.     fread(&dib,sizeof(BMHEAD),1,fp);
  683.  
  684.     fseek(fp,filep,0);
  685.     read_dword(fp);                     /* don't ask me why, skip dummy*/
  686.  
  687.     cu.reserv1 = 0;
  688.     cu.rctype  = 2;
  689.     cu.count   = 1;                        /*images in file*/
  690.     cu.wid     = (UCHAR)dib.width;
  691.     cu.hei     = (UCHAR)(dib.height>>1);   /*important ! AND-MASK in DIB*/
  692.     cu.colors  = (UCHAR)(1<<dib.bitcount);
  693.     cu.reserv2 = 0;
  694.     cu.xhot    = 0;                        /*hotspot set to 0,0, sorry*/
  695.     cu.yhot    = 0;
  696.     cu.DIBsize = dib.size +
  697.                  4L*(ULONG)cu.colors +    /* size of colortable*/
  698.                                           /* size of bitmap*/
  699.                  ((ULONG)cu.wid*(ULONG)cu.hei * (ULONG)dib.bitcount)/8 +
  700.                                           /*size of bitmask*/
  701.                  ((ULONG)cu.wid*(ULONG)cu.hei)/8;
  702.     cu.DIBoff  = sizeof(CURSORHEAD);         /*hope for packed struct's*/
  703.  
  704.     fwrite(&cu,sizeof(CURSORHEAD),1,fpout);
  705.  
  706.     copy_block(fpout,fp,cu.DIBsize);
  707.  
  708.     fseek(fp,fpos,0);
  709.     return(0);
  710.   }
  711. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  712.  
  713. int put_bitmap(fp,fpout,filep)
  714.   FILE *fp,*fpout;
  715.   long filep;
  716.   {
  717.     long fpos;
  718.     char xname[16];
  719.     BMHEAD dib;
  720.     BMFHEAD bfh;
  721.     USHORT len;
  722.     long filelen;
  723.  
  724.     fpos = ftell(fp);
  725.  
  726.     fseek(fp,filep,0);
  727.     fread(&dib,sizeof(BMHEAD),1,fp);
  728.  
  729.     fseek(fp,filep,0);
  730.  
  731.     bfh.sign    = (USHORT)'B' + (USHORT)'M'* 256;
  732.     bfh.fsize   = (ULONG)sizeof(BMFHEAD)+    /*filesize*/
  733.                   dib.size +
  734.                   (ULONG)(1<<dib.bitcount) * 4L +
  735.                   ((ULONG)dib.width*(ULONG)dib.height * (ULONG)dib.bitcount)/8;
  736.  
  737.                         /*offset to bits in file*/
  738.     bfh.offset  = (ULONG)sizeof(BMFHEAD)+
  739.                   dib.size +
  740.                   (ULONG)(1<<dib.bitcount) * 4L;
  741.  
  742.     bfh.reserv1 = bfh.reserv2 = 0;
  743.  
  744.     fwrite(&bfh,sizeof(BMFHEAD),1,fpout);
  745.  
  746.     copy_block(fpout,fp,bfh.fsize - sizeof(BMFHEAD));
  747.  
  748.     fseek(fp,fpos,0);
  749.     return(0);
  750.   }
  751. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  752.  
  753. int put_font(fp,fpout,filep)
  754.   FILE *fp,*fpout;
  755.   long filep;
  756.   {
  757.     long fpos;
  758.     char xname[16];
  759.     USHORT len;
  760.     long filelen;
  761.  
  762.     fpos = ftell(fp);
  763.  
  764.     fseek(fp,filep,0);
  765.     read_word(fp);                /*skip dummy*/
  766.     filelen = read_dword(fp);
  767.  
  768.     fseek(fp,filep,0);    /* and back*/
  769.  
  770.     copy_block(fpout,fp,filelen);
  771.  
  772.     fseek(fp,fpos,0);
  773.     return(0);
  774.   }
  775. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  776.  
  777. int put_strings(fp,fpout,filep,sname,sid,flags)
  778.   FILE *fp,*fpout;
  779.   long filep;
  780.   char *sname;
  781.   USHORT sid;
  782.   USHORT flags;
  783.                     /* ATTENTION: stringtable names not supported
  784.                        (well, officially not allowed but possible,
  785.                          try it !   Maybe I will work on it) */
  786.   {
  787.     long fpos;
  788.     char xname[16];
  789.     char string[257];   /* enough !*/
  790.     UCHAR slen;
  791.     USHORT len;
  792.     USHORT i,n;
  793.     UCHAR *strp;
  794.     long filelen;
  795.  
  796.     fpos = ftell(fp);
  797.  
  798.     fseek(fp,filep,0);
  799.  
  800.     fprintf(fpout,"STRINGTABLE ");
  801.     print_flags(fpout,flags,6);
  802.     fprintf(fpout,"\nBEGIN\n");
  803.     for(i = 0; i < 16; i++)     /*16 strings in a segment */
  804.       {
  805.         slen = read_byte(fp);
  806.         if(slen)                    /* ugly-but-must-be*/
  807.           {
  808.             read_nstring(fp,string,slen);
  809.             strp = string;
  810.             fprintf(fpout,"  %u,\"",i+(sid-1)*16);
  811.             while(*strp)
  812.               {
  813.                 if(*strp < 0x20)
  814.                   fprintf(fpout,"\\%03o",*strp);
  815.                 else if(*strp == '"')
  816.                   fprintf(fpout,"\"\"",*strp);
  817.                 else if(*strp == '\\')
  818.                   fprintf(fpout,"\\\\");
  819.                 else
  820.                   fprintf(fpout,"%c",*strp);
  821.                 strp++;
  822.               }
  823.             fprintf(fpout,"\"\n");
  824.           }
  825.       }
  826.     fprintf(fpout,"END\n");
  827.     fseek(fp,fpos,0);
  828.     return(0);
  829.   }
  830. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  831.  
  832. int put_rcdata(fp,fpout,filep,tlen,rname,rid,flags)
  833.   FILE *fp,*fpout;
  834.   long filep,tlen;
  835.   char *rname;
  836.   USHORT rid;
  837.   USHORT flags;
  838.   {
  839.     long fpos;
  840.     char xname[16];
  841.     USHORT len;
  842.     long filelen;
  843.     USHORT i;
  844.     char first;
  845.     UCHAR c;         /*I don't like accessing arrays to much*/
  846.  
  847.     fpos = ftell(fp);
  848.  
  849.     fseek(fp,filep,0);
  850.     filelen = tlen;
  851.  
  852.     if(rname != NULL)
  853.       fprintf(fpout,"%s RCDATA ",rname);
  854.     else
  855.       fprintf(fpout,"%d RCDATA ",rid);
  856.     print_flags(fpout,flags,10);
  857.  
  858.     fprintf(fpout,"\nBEGIN\n");
  859.  
  860.     first = 1;
  861.     while(filelen)
  862.       {
  863.         len = fread(tmpbuf,1,(USHORT)MIN(filelen,TMPSIZE),fp);
  864.         for(i = 0; i < len; i++)
  865.           {
  866.             c = tmpbuf[i];
  867.  
  868.             if((i & 15) == 0)
  869.               {
  870.                 if(first)       /* are there better ways ??  sure ! */
  871.                   {
  872.                     fprintf(fpout,"\n  \"",c);
  873.                     first = 0;
  874.                   }
  875.                 else
  876.                   fprintf(fpout,"\",\n  \"",c);
  877.               }
  878.  
  879.             if(c >= ' ' && c <= '~')
  880.               fprintf(fpout,"%c",c);
  881.             else
  882.               {
  883.                 if(c == 0)              /* occurs quite often */
  884.                   fprintf(fpout,"\\0");
  885.                 else
  886.                   fprintf(fpout,"\\%03o",c);
  887.               }
  888.  
  889.             if (filelen-i <= 1)          fprintf(fpout,"\"");
  890.           }
  891.         filelen -= len;
  892.       }
  893.     fprintf(fpout,"\nEND\n");
  894.     fseek(fp,fpos,0);
  895.     return(0);
  896.   }
  897. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  898.  
  899. int put_accel(fp,fpout,filep,aname,aid,flags)
  900.   FILE *fp,*fpout;
  901.   long filep;
  902.   char *aname;
  903.   USHORT aid;
  904.   USHORT flags;
  905.   {
  906.     long fpos;
  907.     char xname[16];
  908.     char *vkname;
  909.     UCHAR keytype,keyval;
  910.     USHORT idval;
  911.  
  912.     fpos = ftell(fp);
  913.  
  914.     fseek(fp,filep,0);
  915.     if(aname != NULL)
  916.       fprintf(fpout,"%s ACCELERATORS ",aname);
  917.     else
  918.       fprintf(fpout,"%d ACCELERATORS ",aid);
  919.     print_flags(fpout,flags,9);
  920.  
  921.     fprintf(fpout,"\nBEGIN\n");
  922.     do
  923.       {
  924.         keytype = read_byte(fp);
  925.         keyval  = read_byte(fp);
  926.         read_byte(fp);                           /* skip dummy*/
  927.         idval = read_word(fp);
  928.         if((keytype & 0x01) == 0)                /*ascii */
  929.           {
  930.             if(keyval < 0x20)
  931.               fprintf(fpout,"  \"^%c\",%d",keyval+'@',idval);
  932.             else
  933.               fprintf(fpout,"  \"%c\",%d",keyval,idval);
  934.           }
  935.         else                             /*virtkey*/
  936.           {
  937.             if(keyval >= 'A' && keyval <= 'Z')
  938.               fprintf(fpout,"  \"%c\",%d,VIRTKEY",keyval,idval);
  939.             else if(keyval >= '0' && keyval <= '9')
  940.               fprintf(fpout,"  \"%c\",%d,VIRTKEY",keyval,idval);
  941.             else
  942.               {
  943.                 vkname = get_virttext(keyval);
  944.                 if(vkname != NULL)
  945.                   fprintf(fpout,"  VK_%s,%d,VIRTKEY",vkname,idval);
  946.                 else
  947.                   fprintf(fpout,"  %u,%d,VIRTKEY",keyval,idval);
  948.               }
  949.           }
  950.         if(keytype & 0x02)
  951.           fprintf(fpout,",NOINVERT");
  952.         if(keytype & 0x04)
  953.           fprintf(fpout,",SHIFT");
  954.         if(keytype & 0x08)
  955.           fprintf(fpout,",CONTROL");
  956.         if(keytype & 0x10)
  957.           fprintf(fpout,",ALT");
  958.         fprintf(fpout,"\n");
  959.       } while ( (keytype &0x80) == 0);
  960.     fprintf(fpout,"END\n");
  961.     fseek(fp,fpos,0);
  962.     return(0);
  963.   }
  964. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  965.  
  966. int put_menu(fp,fpout,filep,mname,mid,flags)
  967.   FILE *fp,*fpout;
  968.   long filep;
  969.   char *mname;
  970.   USHORT mid;
  971.   USHORT flags;
  972.   {
  973.     long fpos;
  974.     char xname[16];
  975.     int indent;
  976.     USHORT mflag,idval;
  977.     char menustr[256],*msp;    /*should be enough*/
  978.     char levelend[32],level;   /* have you seen an application
  979.                                   32 menu-levels deep ?? */
  980.  
  981.     for(level = 0; level < 32;level++)  levelend[level] = 0;
  982.     level = 0;
  983.  
  984.     fpos = ftell(fp);
  985.  
  986.     fseek(fp,filep,0);
  987.     read_dword(fp);                        /* unused*/
  988.  
  989.     if(mname != NULL)
  990.       fprintf(fpout,"%s MENU ",mname);
  991.     else
  992.       fprintf(fpout,"%d MENU ",mid);
  993.     print_flags(fpout,flags,4);
  994.     fprintf(fpout,"\nBEGIN\n");
  995.  
  996.     indent = INDENTVAL;
  997.     level++;
  998.     levelend[0] = 1;
  999.  
  1000.     while(level > 0)
  1001.       {
  1002.         mflag = read_word(fp);                    /*menu-flags*/
  1003.         if(!(mflag & MF_POPUP))
  1004.           idval = read_word(fp);                  /*id-value*/
  1005.  
  1006.         read_string(fp,menustr);
  1007.  
  1008.         if(mflag & MF_POPUP)
  1009.           {
  1010.             fprintf(fpout,"%sPOPUP \"%s\"",SPC(indent),menustr);
  1011.             if(mflag & MF_GRAYED)        fprintf(fpout,", GRAYED");
  1012.             if(mflag & MF_DISABLED)      fprintf(fpout,", INACTIVE");
  1013.             if(mflag & MF_CHECKED)       fprintf(fpout,", CHECKED");
  1014.             if(mflag & MF_MENUBARBREAK)  fprintf(fpout,", MENUBARBREAK");
  1015.             if(mflag & MF_MENUBREAK)     fprintf(fpout,", MENUBREAK");
  1016.             fprintf(fpout,"\n%sBEGIN\n",SPC(indent));
  1017.             indent += INDENTVAL;
  1018.             if(mflag & MF_END)
  1019.               {
  1020.                 levelend[level] = 1;
  1021.               }
  1022.             level++;
  1023.           }
  1024.         else
  1025.           {
  1026.             if(menustr[0] || (mflag & IS_MENUOPT))
  1027.               fprintf(fpout,"%sMENUITEM \"%s\", %d",SPC(indent),menustr,idval);
  1028.             else
  1029.               fprintf(fpout,"%sMENUITEM SEPARATOR",SPC(indent));
  1030.  
  1031.             if(mflag & MF_GRAYED)        fprintf(fpout,", GRAYED");
  1032.             if(mflag & MF_DISABLED)      fprintf(fpout,", INACTIVE");
  1033.             if(mflag & MF_CHECKED)       fprintf(fpout,", CHECKED");
  1034.             if(mflag & MF_MENUBARBREAK)  fprintf(fpout,", MENUBARBREAK");
  1035.             if(mflag & MF_MENUBREAK)     fprintf(fpout,", MENUBREAK");
  1036.             fprintf(fpout,"\n");
  1037.             if(mflag & MF_END)
  1038.               {
  1039.                 indent -= INDENTVAL;
  1040.                 level--;
  1041.                 fprintf(fpout,"%sEND\n",SPC(indent));
  1042.                 while(levelend[level] && level)
  1043.                   {
  1044.                     indent -= INDENTVAL;
  1045.                     level--;
  1046.                     fprintf(fpout,"%sEND\n",SPC(indent));
  1047.                   }
  1048.               }
  1049.           }
  1050.       }
  1051.     fseek(fp,fpos,0);
  1052.     return(0);
  1053.   }
  1054. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1055.  
  1056. int put_dialog(fp,fpout,filep,dname,did,flags)
  1057.   FILE *fp,*fpout;
  1058.   long filep;
  1059.   char *dname;
  1060.   USHORT did;
  1061.   USHORT flags;
  1062.   {
  1063.     long fpos;
  1064.     char xname[16];
  1065.     USHORT len;
  1066.     ULONG rstyle;
  1067.     UCHAR rclass;
  1068.     UCHAR nctrl;                    /* # of controls in box*/
  1069.     USHORT fontsize;
  1070.     char fontname[64];
  1071.     USHORT x,y,wid,hei,idval;
  1072.     UCHAR text[256],*txtp;                 /* should be enough*/
  1073.     char classname[256],*classp;
  1074.     int i;
  1075.     int numref;
  1076.     long filelen;
  1077.  
  1078.     fpos = ftell(fp);
  1079.  
  1080.     fseek(fp,filep,0);    /* and back*/
  1081.  
  1082.     rstyle = read_dword(fp);        /* dlgbox-style*/
  1083.     nctrl = read_byte(fp);          /* # controls*/
  1084.     x     = read_word(fp);
  1085.     y     = read_word(fp);
  1086.     wid   = read_word(fp);
  1087.     hei   = read_word(fp);
  1088.  
  1089.     if(dname != NULL)
  1090.       fprintf(fpout,"%s DIALOG ",dname);
  1091.     else
  1092.       fprintf(fpout,"%d DIALOG ",did);
  1093.     print_flags(fpout,flags,5);
  1094.  
  1095.     fprintf(fpout," %d, %d, %d, %d\n",x,y,wid,hei);
  1096.     fprintf(fpout,"STYLE ");
  1097.     print_styles(fpout,rstyle,0);
  1098.     fprintf(fpout,"\n");
  1099.  
  1100.     if(read_textorid(fp,text,&numref) == GOT_ID)   /* MENU name*/
  1101.       fprintf(fpout,"MENU %d\n",numref);
  1102.     else if(text[0])
  1103.       fprintf(fpout,"MENU \"%s\"\n",text);
  1104.  
  1105.     if(read_textorid(fp,text,&numref) == GOT_ID)   /* CLASS name*/
  1106.       fprintf(fpout,"CLASS %d\n",numref);
  1107.     else if(text[0])
  1108.       fprintf(fpout,"CLASS \"%s\"\n",text);
  1109.  
  1110.     if(read_textorid(fp,text,&numref) == GOT_ID)   /* CAPTION */
  1111.       fprintf(fpout,"CAPTION %d\n",numref);
  1112.     else if(text[0])
  1113.       fprintf(fpout,"CAPTION \"%s\"\n",text);
  1114.  
  1115.     if(rstyle & DS_SETFONT)
  1116.       {
  1117.         fontsize = read_word(fp);
  1118.         read_string(fp,fontname);
  1119.         fprintf(fpout,"FONT %u,\"%s\"\n",fontsize,fontname);
  1120.       }
  1121.  
  1122.  
  1123.     fprintf(fpout,"\nBEGIN\n");
  1124.  
  1125.     for(i = 0; i < nctrl;i++)
  1126.       {
  1127.         x     = read_word(fp);
  1128.         y     = read_word(fp);
  1129.         wid   = read_word(fp);
  1130.         hei   = read_word(fp);
  1131.         idval = read_word(fp);
  1132.         rstyle = read_dword(fp);         /* ctrl-style*/
  1133.         rclass = read_byte(fp);          /* class (std or by name) */
  1134.         if(rclass < 0x80 || rclass > 0x85)   /* non standard class*/
  1135.           {
  1136.             classname[0] = rclass;
  1137.             if(rclass)
  1138.               read_string(fp,classname+1);
  1139.           }
  1140.         else
  1141.           {
  1142.             strcpy(classname,stdclassname[rclass & 0x0f]);
  1143.           }
  1144.  
  1145.         if(read_textorid(fp,text,&numref) == GOT_ID)
  1146.             fprintf(fpout,"  CONTROL %d, %d,\"%s\",",
  1147.                            numref,idval,classname,rstyle,x,y,wid,hei);
  1148.         else
  1149.             fprintf(fpout,"  CONTROL \"%s\", %d,\"%s\",",
  1150.                           text,idval,classname,rstyle,x,y,wid,hei);
  1151.  
  1152.         read_byte(fp);                        /*there's another 0*/
  1153.         if(rclass < 0x80 || rclass > 0x85)   /* non standard class*/
  1154.           {
  1155.             fprintf(fpout,"0x%08lX",rstyle);
  1156.           }
  1157.         else
  1158.           {
  1159.             print_styles(fpout,rstyle,rclass);
  1160.           }
  1161.         fprintf(fpout,",%d, %d, %d, %d\n",
  1162.                        x,y,wid,hei);
  1163.       }
  1164.     fprintf(fpout,"END\n");
  1165.     fseek(fp,fpos,0);
  1166.     return(0);
  1167.   }
  1168. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1169.  
  1170. int put_nametab(fp,fpout,filep)
  1171.   FILE *fp,*fpout;
  1172.   long filep;
  1173.   {
  1174.     long fpos;
  1175.     char xname[16];
  1176.     char rcname[256];
  1177.     USHORT len,rctype,rcnum,i;
  1178.     long filelen;
  1179.  
  1180.     fpos = ftell(fp);
  1181.  
  1182.     fseek(fp,filep,0);    /* and back*/
  1183.  
  1184.     while(len = read_word(fp))
  1185.       {
  1186.         rctype = read_word(fp);
  1187.         rctype &= 0x000f;
  1188.         rctype %= 11;             /* refs to icons are refs to iconheaders
  1189.                                      same for bitmaps, think about that */
  1190.         rcnum = read_word(fp);
  1191.         rcnum &= 0x7fff;
  1192.         read_byte(fp);            /* skip 1 byte */
  1193.         fread(rcname,1,len-7,fp);   /* may use read_string, but this is safe*/
  1194.         fprintf(fpout,"%s %s @%d\n",rcname,resname[rctype],rcnum);
  1195.       }
  1196.     fseek(fp,fpos,0);
  1197.     return(0);
  1198.   }
  1199. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1200.  
  1201. int print_styles(fpout,rstyle,rclass)
  1202.   FILE *fpout;
  1203.   ULONG rstyle;
  1204.   UCHAR rclass;
  1205.   {
  1206.                              /* common window styles*/
  1207.     fprintf(fpout,"0");      /* sorry!*/
  1208.     if(rstyle & WS_VISIBLE)
  1209.       fprintf(fpout,"|WS_VISIBLE");
  1210.     if(rstyle & WS_POPUP)
  1211.       fprintf(fpout,"|WS_POPUP");
  1212.     if(rstyle & WS_CHILD)
  1213.       fprintf(fpout,"|WS_CHILD");
  1214.     if(rstyle & WS_MINIMIZE)
  1215.       fprintf(fpout,"|WS_MINIMIZE");
  1216.     if(rstyle & WS_DISABLED)
  1217.       fprintf(fpout,"|WS_DISABLED");
  1218.     if(rstyle & WS_DISABLED)
  1219.       fprintf(fpout,"|WS_DISABLED");
  1220.     if(rstyle & WS_CLIPSIBLINGS)
  1221.       fprintf(fpout,"|WS_CLIPSIBLINGS");
  1222.     if(rstyle & WS_CLIPCHILDREN)
  1223.       fprintf(fpout,"|WS_CLIPCHILDREN");
  1224.     if(rstyle & WS_MAXIMIZE)
  1225.       fprintf(fpout,"|WS_MAXIMIZE");
  1226.     if((rstyle & WS_CAPTION) == WS_CAPTION)
  1227.       fprintf(fpout,"|WS_CAPTION");
  1228.     else
  1229.       {
  1230.         if(rstyle & WS_BORDER)
  1231.           fprintf(fpout,"|WS_BORDER");
  1232.         if(rstyle & WS_DLGFRAME)
  1233.           fprintf(fpout,"|WS_DLGFRAME");
  1234.       }
  1235.     if(rstyle & WS_VSCROLL)
  1236.       fprintf(fpout,"|WS_VSCROLL");
  1237.     if(rstyle & WS_HSCROLL)
  1238.       fprintf(fpout,"|WS_HSCROLL");
  1239.     if(rstyle & WS_SYSMENU)
  1240.       fprintf(fpout,"|WS_SYSMENU");
  1241.     if(rstyle & WS_THICKFRAME)
  1242.       fprintf(fpout,"|WS_THICKFRAME");
  1243.     if(rstyle & WS_GROUP)
  1244.       fprintf(fpout,"|WS_GROUP");
  1245.     if(rstyle & WS_TABSTOP)
  1246.       fprintf(fpout,"|WS_TABSTOP");
  1247.     if(rstyle & WS_MINIMIZEBOX)
  1248.       fprintf(fpout,"|WS_MINIMIZEBOX");
  1249.     if(rstyle & WS_MAXIMIZEBOX)
  1250.       fprintf(fpout,"|WS_MAXIMIZEBOX");
  1251.     if(rclass == 0)                     /* is dialog-box style*/
  1252.       {
  1253.         if(rstyle & DS_ABSALIGN)
  1254.           fprintf(fpout,"|DS_ABSALIGN");
  1255.         if(rstyle & DS_SYSMODAL)
  1256.           fprintf(fpout,"|DS_SYSMODAL");
  1257.         if(rstyle & DS_LOCALEDIT)
  1258.           fprintf(fpout,"|DS_LOCALEDIT");
  1259.         if(rstyle & DS_SETFONT)
  1260.           fprintf(fpout,"|DS_SETFONT");
  1261.         if(rstyle & DS_MODALFRAME)
  1262.           fprintf(fpout,"|DS_MODALFRAME");
  1263.         if(rstyle & DS_NOIDLEMSG)
  1264.           fprintf(fpout,"|DS_NOIDLEMSG");
  1265.       }
  1266.     else if(rclass == 0x80)                     /* button styles*/
  1267.       {
  1268.         fprintf(fpout,"|%s",button_text[rstyle & 0x0fL]);
  1269.         if(rstyle & BS_LEFTTEXT)
  1270.           fprintf(fpout,"|BS_LEFTTEXT");
  1271.       }
  1272.     else if(rclass == 0x81)                     /* edit styles*/
  1273.       {
  1274.         fprintf(fpout,"|%s",edit_text[rstyle & 0x03L]);
  1275.         if(rstyle & ES_MULTILINE)
  1276.           fprintf(fpout,"|ES_MULTILINE");
  1277.         if(rstyle & ES_UPPERCASE)
  1278.           fprintf(fpout,"|ES_UPPERCASE");
  1279.         if(rstyle & ES_LOWERCASE)
  1280.           fprintf(fpout,"|ES_LOWERCASE");
  1281.         if(rstyle & ES_PASSWORD)
  1282.           fprintf(fpout,"|ES_PASSWORD");
  1283.         if(rstyle & ES_AUTOVSCROLL)
  1284.           fprintf(fpout,"|ES_AUTOVSCROLL");
  1285.         if(rstyle & ES_AUTOHSCROLL)
  1286.           fprintf(fpout,"|ES_AUTOHSCROLL");
  1287.         if(rstyle & ES_NOHIDESEL)
  1288.           fprintf(fpout,"|ES_NOHIDESEL");
  1289.         if(rstyle & ES_OEMCONVERT)
  1290.           fprintf(fpout,"|ES_OEMCONVERT");
  1291.       }
  1292.     else if(rclass == 0x82)                     /* static styles*/
  1293.       {
  1294.         fprintf(fpout,"|%s",static_text[rstyle & 0x0fL]);
  1295.         if(rstyle & SS_NOPREFIX)
  1296.           fprintf(fpout,"|SS_NOPREFIX");
  1297.       }
  1298.     else if(rclass == 0x83)                     /* listbox styles*/
  1299.       {
  1300.         if(rstyle & LBS_NOTIFY)
  1301.           fprintf(fpout,"|LBS_NOTIFY");
  1302.         if(rstyle & LBS_SORT)
  1303.           fprintf(fpout,"|LBS_SORT");
  1304.         if(rstyle & LBS_NOREDRAW)
  1305.           fprintf(fpout,"|LBS_NOREDRAW");
  1306.         if(rstyle & LBS_MULTIPLESEL)
  1307.           fprintf(fpout,"|LBS_MULTIPLESEL");
  1308.         if(rstyle & LBS_OWNERDRAWFIXED)
  1309.           fprintf(fpout,"|LBS_OWNERDRAWFIXED");
  1310.         if(rstyle & LBS_OWNERDRAWVARIABLE)
  1311.           fprintf(fpout,"|LBS_OWNERDRAWVARIABLE");
  1312.         if(rstyle & LBS_HASSTRINGS)
  1313.           fprintf(fpout,"|LBS_HASSTRINGS");
  1314.         if(rstyle & LBS_USETABSTOPS)
  1315.           fprintf(fpout,"|LBS_USETABSTOPS");
  1316.         if(rstyle & LBS_NOINTEGRALHEIGHT)
  1317.           fprintf(fpout,"|LBS_NOINTEGRALHEIGHT");
  1318.         if(rstyle & LBS_MULTICOLUMN)
  1319.           fprintf(fpout,"|LBS_MULTICOLUMN");
  1320.         if(rstyle & LBS_WANTKEYBOARDINPUT)
  1321.           fprintf(fpout,"|LBS_WANTKEYBOARDINPUT");
  1322.         if(rstyle & LBS_EXTENDEDSEL)
  1323.           fprintf(fpout,"|LBS_EXTENDEDSEL");
  1324.       }
  1325.     else if(rclass == 0x84)                     /* scrollbar styles*/
  1326.       {
  1327.  
  1328.         if(rstyle & SBS_VERT)
  1329.           {
  1330.             fprintf(fpout,"|SBS_VERT");
  1331.             if(rstyle & SBS_LEFTALIGN)
  1332.               fprintf(fpout,"|SBS_LEFTALIGN");
  1333.             if(rstyle & SBS_RIGHTALIGN)
  1334.               fprintf(fpout,"|SBS_RIGHTALIGN");
  1335.           }
  1336.         else
  1337.           {
  1338.             fprintf(fpout,"|SBS_HORZ");
  1339.             if(rstyle & SBS_TOPALIGN)
  1340.               fprintf(fpout,"|SBS_TOPALIGN");
  1341.             if(rstyle & SBS_BOTTOMALIGN)
  1342.               fprintf(fpout,"|SBS_BOTTOMALIGN");
  1343.           }
  1344.  
  1345.         if(rstyle & SBS_SIZEBOX)
  1346.           {
  1347.             fprintf(fpout,"|SBS_SIZEBOX");
  1348.             if(rstyle & SBS_SIZEBOXTOPLEFTALIGN)
  1349.               fprintf(fpout,"|SBS_SIZEBOXTOPLEFTALIGN");
  1350.             if(rstyle & SBS_SIZEBOXBOTTOMRIGHTALIGN)
  1351.               fprintf(fpout,"|SBS_SIZEBOXBOTTOMRIGHTALIGN");
  1352.           }
  1353.       }
  1354.     else if(rclass == 0x85)                     /* combobox styles*/
  1355.       {
  1356.         fprintf(fpout,"|%s",combo_text[rstyle & 0x03L]);
  1357.         if(rstyle & CBS_OWNERDRAWFIXED)
  1358.           fprintf(fpout,"|CBS_OWNERDRAWFIXED");
  1359.         if(rstyle & CBS_OWNERDRAWVARIABLE)
  1360.           fprintf(fpout,"|CBS_OWNERDRAWVARIABLE");
  1361.         if(rstyle & CBS_AUTOHSCROLL)
  1362.           fprintf(fpout,"|CBS_AUTOHSCROLL");
  1363.         if(rstyle & CBS_OEMCONVERT)
  1364.           fprintf(fpout,"|CBS_OEMCONVERT");
  1365.         if(rstyle & CBS_SORT)
  1366.           fprintf(fpout,"|CBS_SORT");
  1367.         if(rstyle & CBS_HASSTRINGS)
  1368.           fprintf(fpout,"|CBS_HASSTRINGS");
  1369.         if(rstyle & CBS_NOINTEGRALHEIGHT)
  1370.           fprintf(fpout,"|CBS_NOINTEGRALHEIGHT");
  1371.       }
  1372.     return(0);
  1373.   }
  1374. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1375.  
  1376. char *get_virttext(val)
  1377.   UCHAR val;
  1378.   {
  1379.     TEXTTAB *tp;
  1380.     tp = virt_text;
  1381.     while(tp->val)
  1382.       {
  1383.         if(tp->val == val)    return(tp->text);
  1384.         tp++;
  1385.       }
  1386.     return(NULL);
  1387.   }
  1388.  
  1389. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1390. /* helper functions              */
  1391. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1392.  
  1393. int read_string(fp,str)          /* read string with terminating 0*/
  1394.   FILE *fp;
  1395.   char *str;
  1396.   {
  1397.     int cnt;
  1398.  
  1399.     cnt = 0;
  1400.                              /*get string with terminating 0*/
  1401.     do { fread(str,1,1,fp); cnt++;} while(*str++);
  1402.     return(cnt-1);           /* return strlen */
  1403.   }
  1404. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1405.  
  1406. int read_nstring(fp,str,n)      /* read string of length n,
  1407.                                    add terminating 0*/
  1408.   FILE *fp;
  1409.   char *str;
  1410.   USHORT n;
  1411.   {
  1412.     fread(str,n,1,fp);       /*size n, because we want it with
  1413.                                only one read (say 'hi' to *nix & *icrosoft)*/
  1414.     str[n] = '\0';
  1415.     return(n);               /* return strlen */
  1416.   }
  1417. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1418.  
  1419. USHORT read_word(fp)
  1420.   FILE *fp;
  1421.   {
  1422.     USHORT tmp;
  1423.     fread(&tmp,2,1,fp);
  1424.     return(tmp);
  1425.   }
  1426. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1427.  
  1428. ULONG read_dword(fp)
  1429.   FILE *fp;
  1430.   {
  1431.     ULONG tmp;
  1432.     fread(&tmp,4,1,fp);
  1433.     return(tmp);
  1434.   }
  1435. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1436.  
  1437. UCHAR read_byte(fp)
  1438.   FILE *fp;
  1439.   {
  1440.     UCHAR tmp;
  1441.     fread(&tmp,1,1,fp);
  1442.     return(tmp);
  1443.   }
  1444. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1445.  
  1446. int copy_block(fpto,fp,size)
  1447.   FILE *fpto,*fp;
  1448.   ULONG size;
  1449.   {
  1450.     USHORT len;
  1451.  
  1452.     while(size)
  1453.       {
  1454.         len = fread(tmpbuf,1,(USHORT)MIN(size,TMPSIZE),fp);
  1455.         fwrite(tmpbuf,1,len,fpto);
  1456.         size -= (ULONG)len;
  1457.       }
  1458.     return(0);
  1459.   }
  1460. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1461.  
  1462. int read_textorid(fp,text,idp)
  1463.   FILE *fp;
  1464.   char *text;
  1465.   int *idp;
  1466.   {
  1467.     UCHAR chkc;
  1468.  
  1469.     chkc = read_byte(fp);
  1470.     if(chkc == 0xff)  /* undocumented numerical reference*/
  1471.       {
  1472.         *idp = read_word(fp);
  1473.         return(GOT_ID);
  1474.       }
  1475.     text[0] = chkc;
  1476.     if(chkc)      read_string(fp,text+1);    /*there is text*/
  1477.     return(GOT_TEXT);
  1478.   }
  1479. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1480.  
  1481. char *lookup_name(rce,type)
  1482.   RCENTRY *rce;
  1483.   USHORT type;
  1484.   {
  1485.     int i;
  1486.  
  1487.     type &= 0x000f;
  1488.     type %= 11;
  1489.     for(i = 0; i < ntentry; i++)
  1490.       {
  1491.         if(((rce->id & 0x7fff) == (nametab[i].num & 0x7fff)) &&
  1492.            (type == nametab[i].type))
  1493.           return(nametab[i].name);
  1494.       }
  1495.     return(NULL);
  1496.   }
  1497. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1498.  
  1499. int print_flags(fp,flg,type)
  1500.   FILE *fp;
  1501.   USHORT flg;
  1502.   USHORT type;
  1503.   {
  1504.     if(type != 2)   /* BITMAP*/
  1505.       {
  1506.         if( (flg & FLAG_MASK) == (MEMF_DISC|MEMF_MOVE))
  1507.           return(0);   /* is default*/
  1508.       }
  1509.     else
  1510.       {
  1511.         if( (flg & FLAG_MASK) == MEMF_MOVE)
  1512.           return(0);
  1513.       }
  1514.  
  1515.     if(flg & MEMF_PREL)           /*PRELOAD*/
  1516.       fprintf(fp,"PRELOAD ");
  1517.     else
  1518.       fprintf(fp,"LOADONCALL ");
  1519.  
  1520.     if(flg & MEMF_DISC)           /*DISCARDABLE*/
  1521.       fprintf(fp,"DISCARDABLE ");
  1522.  
  1523.     if(flg & MEMF_MOVE)           /*MOVEABLE*/
  1524.       fprintf(fp,"MOVEABLE ");
  1525.     else
  1526.       fprintf(fp,"FIXED ");
  1527.  
  1528.  
  1529.     return(0);
  1530.   }
  1531. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1532.